package com.zlzxm.shoesmarket.view.adapter;

import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityRepositoryInOutNote;

import org.jetbrains.annotations.NotNull;

/**
 * CREATE BY zlzxm ON 3/14/21
 */
public class ADRepositoryInOutNote extends BaseQuickAdapter<EntityRepositoryInOutNote, BaseViewHolder> {

    private static final String CODE = "货号: ";
    private static final String BRAND = "品牌: ";
    private static final String SIZE = "尺码: ";
    private static final String TIME = "时间: ";
    private static final String PRICE = "单价: ";
    private static final String NUM = "数量: ";
    private static final String PROFIT = "利润: ";

    RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(0.85f);

    ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.parseColor("#FE4C40"));

    public ADRepositoryInOutNote() {
        super(R.layout.item_repository_in_out_note);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, EntityRepositoryInOutNote entity) {

        SpannableString ssCode = new SpannableString(CODE+entity.getCode());
        ssCode.setSpan(relativeSizeSpan,3,ssCode.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvCode,ssCode);

        SpannableString ssBrand = new SpannableString(BRAND+entity.getBrand());
        ssBrand.setSpan(relativeSizeSpan,3,ssBrand.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvBrand,ssBrand);

        SpannableString ssTime = new SpannableString(TIME+entity.getTime());
        ssTime.setSpan(relativeSizeSpan,3,ssTime.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvTime,ssTime);


        SpannableString ssNum = new SpannableString(NUM+entity.getNum());
        ssNum.setSpan(relativeSizeSpan,3,ssNum.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvNum,ssNum);

        SpannableString ssSize = new SpannableString(SIZE+entity.getSize());
        ssSize.setSpan(relativeSizeSpan,3,ssSize.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvSize,ssSize);




        SpannableString ssPrice = new SpannableString(PRICE+entity.getPrice());
        ssPrice.setSpan(relativeSizeSpan,3,ssPrice.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssPrice.setSpan(foregroundColorSpan,3,ssPrice.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);


        holder.setText(R.id.tvPrice,ssPrice);


        SpannableString ssProfit = new SpannableString(PROFIT+entity.getProfit());
        ssProfit.setSpan(relativeSizeSpan,3,ssProfit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssProfit.setSpan(foregroundColorSpan,3,ssProfit.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.setText(R.id.tvProfit,ssProfit);


        RequestOptions requestOptions  = new RequestOptions().transform(new CenterCrop(),new RoundedCorners(ZViewHelp.dpTopx(getContext(),3)));

        Glide.with(getContext())
                .load(entity.getFace())
                .apply(requestOptions)
                .into((ImageView) holder.getView(R.id.ivFace));

    }
}
